package zcjq.d907;

import java.util.Arrays;
import java.util.Scanner;

public class P111 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] params = Arrays.stream(scanner.nextLine().trim().split(" ")).mapToInt(s -> Integer.parseInt(s)).toArray();
        int N = params[0];
        int K = params[1];
        int[][] board = new int[N][];
        for (int i = 0; i < N; i++) {
            board[i] = Arrays.stream(scanner.nextLine().trim().split(" ")).mapToInt((s -> Integer.parseInt(s))).toArray();
        }
        //输出
        int[][] result = new int[N * K][N * K];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                int p = board[i][j];
                for (int x = K * i; x < K * (i + 1); x++) {
                    for (int y = K * j; y < K * (j + 1); y++) {
                        result[x][y] = p;
                    }
                }
            }
        }
        for (int[] row : result) {
            StringBuilder sb = new StringBuilder();
            for (int col : row) {
                sb.append(col + " ");
            }
            sb.deleteCharAt(sb.length() - 1);
            System.out.println(sb.toString());
        }
    }
}
